import { Ref, ref } from "vue";
export function useCall({
  callInfo,
  customerData,
  dataList
}: {
  callInfo: Ref<any>;
  customerData: Ref<any>;
  dataList: Ref<any[]>;
}) {
  const callShow = ref(false);

  const showCallPop = () => (callShow.value = true);
  const closeCallPop = () => (callShow.value = false);
  const handleCallNext = () => {
    console.log("handleCallNext", customerData.value);
    const index = dataList.value.findIndex(
      item => item.id == customerData.value.id
    );
    let nextIndex = index + 1;
    const total = dataList.value.length;
    if (index != -1) {
      if (nextIndex >= total) {
        nextIndex = 0;
      }
      // 直接重置为初始状态 免得污染到新的数据
      callInfo.value = { status: 0 };
      customerData.value = dataList.value[nextIndex];
      console.log("customerData", customerData.value);
    }
  };
  return { dataList, callShow, handleCallNext, showCallPop, closeCallPop };
}
